package com.bootdo.stock.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.stock.domain.StockDO;
import com.bootdo.stock.service.StockService;
import com.bootdo.system.domain.UserDO;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.ShiroUtils;

/**
 * 库存表
 * 
 * @author clq
 * @date 2018-05-14 18:10:50
 */
 
@Controller
@RequestMapping("/stock/stock")
public class StockController {
	@Autowired
	private StockService stockService;
	
	@GetMapping()
	@RequiresPermissions("stock:stock:stock")
	String Stock(){
	    return "stock/stock/stock";
	}

	@GetMapping("/stockP")
	@RequiresPermissions("stock:stock:stockP")
	String StockP(){
		return "stock/stock/stockP";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("stock:stock:stock")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<StockDO> stockList = stockService.list(query);
		int total = stockService.count(query);
		PageUtils pageUtils = new PageUtils(stockList, total);
		return pageUtils;
	}

	@ResponseBody
	@GetMapping("/listP")
	@RequiresPermissions("stock:stock:stockP")
	public PageUtils listP(@RequestParam Map<String, Object> params){
		//查询列表数据
		UserDO user = ShiroUtils.getUser();
		if(user.getProviderId() != null) {
			params.put("pid", user.getProviderId());
		}else {
			params.put("pid", "");
		}
		Query query = new Query(params);
		List<StockDO> stockList = stockService.listP(query);
		int total = stockService.countP(query);
		PageUtils pageUtils = new PageUtils(stockList, total);
		return pageUtils;
	}
	
}
